package cn.bigfire.wedesk.store;

import cn.bigfire.wedesk.bean.Wedesk;
import cn.bigfire.wedesk.util.ScreenData;
import cn.bigfire.wedesk.util.ScreenTimer;
import io.netty.channel.Channel;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;

public class Stores {

    //自己的Channel用于给服务器发消息用。
    public static Channel channel;

    //我的账号下，当前在线的设备
    private static Map<String, Wedesk.PCInfo> pcOnlineMap = new HashMap<>();
    private static Map<String, Wedesk.Ctrl> ctrlMap = new HashMap<>();
    public static ArrayBlockingQueue<ScreenData> blockingQueue = new ArrayBlockingQueue<>(16);

    public static void updateDevices(Map<String, Wedesk.PCInfo> pcInfos) {
        pcOnlineMap = pcInfos;
    }

    public static Wedesk.PCInfo getDevicesById(String channelId) {
        return pcOnlineMap.get(channelId);
    }

    public static Map<String, Wedesk.PCInfo> getDevices(Map<String, Wedesk.PCInfo> devices) {
        return pcOnlineMap;
    }

    public static boolean hasCtrl(){
        return ctrlMap.size() > 0;
    }


    public static void addCtrlOpen(Wedesk.Ctrl ctrlOpenReq) {
        ctrlMap.put(ctrlOpenReq.getFromCid(), ctrlOpenReq);
        ScreenTimer.before = null;
    }

    public static void removeCtrlOpen(Wedesk.Ctrl ctrlExecReq) {
        ctrlMap.remove(ctrlExecReq.getFromCid());
        ScreenTimer.before = null;
    }



}
